package com.xyht.sca_s.student_manage_system.modules.teachAndStaffCheckInApplication.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonCodeEnum;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonResult;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.modules.teachAndStaffCheckInApplication.entity.SmsTeachAdministrativePromiseManage;
import com.xyht.sca_s.student_manage_system.modules.teachAndStaffCheckInApplication.entity.vo.SmsTeachAdministrativePromiseManageVO;
import com.xyht.sca_s.student_manage_system.modules.teachAndStaffCheckInApplication.mapper.SmsTeachAdministrativePromiseManageMapper;
import com.xyht.sca_s.student_manage_system.modules.teachAndStaffCheckInApplication.service.SmsTeachAdministrativePromiseManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import static com.xyht.sca_s.student_manage_system.common.util.ParamCheckUtil.isNullOrEmpty;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author XYHT
 * @since 2023-07-05
 */
@Service
public class SmsTeachAdministrativePromiseManageServiceImpl extends ServiceImpl<SmsTeachAdministrativePromiseManageMapper, SmsTeachAdministrativePromiseManage> implements SmsTeachAdministrativePromiseManageService {
    @Autowired
    SmsTeachAdministrativePromiseManageMapper smsTeachAdministrativePromiseManageMapper;
    @Override
    public ResponseResult addPromise(SmsTeachAdministrativePromiseManageVO promiseManageVO) {
        if(isNullOrEmpty(promiseManageVO.getPromise())){
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }
        SmsTeachAdministrativePromiseManage manage = new SmsTeachAdministrativePromiseManage();
        manage.setPromise(promiseManageVO.getPromise());
        smsTeachAdministrativePromiseManageMapper.insert(manage);
        return CommonResult.success();
    }

    @Override
    public ResponseResult select() {
        SmsTeachAdministrativePromiseManage one = this.getOne(new LambdaQueryWrapper<SmsTeachAdministrativePromiseManage>()
                .orderByDesc(SmsTeachAdministrativePromiseManage::getUpdateTime)
                .last("limit 1")
        );
        SmsTeachAdministrativePromiseManageVO manageVO = BeanUtil.copyProperties(one, SmsTeachAdministrativePromiseManageVO.class);
        return CommonResult.success(manageVO);
    }
}
